import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileCharArr {
    public static void main(String[] args) throws IOException {
        FileReader fr = null;
        try {
            File file = new File("IO/file/1.txt");
            fr = new FileReader(file);
            char[] cbuf = new char[5];
            int len;
            // 每次读入char[]
            while ((len = fr.read(cbuf))!=-1) { //判断len是否等于-1
//                for (int i = 0; i < cbuf.length; i++) {
//                    System.out.print(cbuf[i]);
//                }
                //上述问题：最后一次读，char[]，后面的没覆盖，也会输出出来。
                for (int i = 0; i < len; i++) {
                    System.out.print(cbuf[i]);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fr!=null)
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
}
